Skip to content

[Rebase & FF] Make PageTableHal stateful and eliminate global statics from test code - #222

Open
vineelko wants to merge 2 commits into
mainfrom
users/vineelko/remove_global_statics_0817
Open

[Rebase & FF] Make PageTableHal stateful and eliminate global statics from test code#222
vineelko wants to merge 2 commits into
mainfrom
users/vineelko/remove_global_statics_0817

Conversation

@vineelko

Copy link
Copy Markdown
Contributor

Description

Make PageTableHal a stateful (&self) trait

By declaring only associated functions in the PageTableHal trait, it
becomes impossible to cleanly define any kind of state that can be
controlled for testing purposes. Also, the current usage of these
associated functions is not truly stateless. Instead, their state is
hidden behind the hardware registers. This may be fine for the non test
code, where the generic Arch type parameter bounded by PageTableHal is
passed all the way from PageTable to PageTableHal implicitly. But its
usage complicates testing by forcing hacky global statics, and on top
of that, to keep those statics from pounding on each other forces to
serialize the tests with serial_test.

This commit converts every PageTableHal method from an associated
function to a &self method so tests can carry per instance state
instead of relying on globals. The arch instance is now plumbed
explicitly through the paging core rather than being invoked purely by
generic type.

No functional change to mapping/query/unmap behavior.

Make DummyArch stateful to drop serial_test

Replace the global ACTIVE/BASE statics in the paging unit tests with per
instance AtomicBool/AtomicU64 fields on DummyArch, shared with
DummyAllocator via Rc. Each test now owns its own arch state
instead of mutating process wide globals, so the tests no longer
need #[serial] and can run in parallel.

This also makes the tests more useful under nextest.


  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

Booted in Q35, Ran repeated rounds of tests both under cargo make test and cargo nextest run

Integration Instructions

NA

Comment thread src/paging.rs
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.61364% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/paging.rs 91.89% 9 Missing ⚠️
src/aarch64.rs 95.12% 2 Missing ⚠️
src/x64.rs 91.67% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread src/paging.rs Outdated
Comment thread src/x64.rs Outdated
Comment thread src/paging.rs Outdated
Comment thread src/paging.rs
@@ -241,6 +246,7 @@ impl<P: PageAllocator, Arch: PageTableHal> PageTableInternal<P, Arch> {

fn map_memory_region_internal(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of parameters is starting to reach the point that it's probably worth considering a context struct where it makes sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every api is slightly different we probably need different context structures. I will try to take it as a separate PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was one of the more extreme cases I found.

@vineelko
vineelko force-pushed the users/vineelko/remove_global_statics_0817 branch 2 times, most recently from 69842c2 to ea29786 Compare August 21, 2026 00:10
By declaring only associated functions in the PageTableHal trait, it
becomes impossible to cleanly define any kind of state that can be
controlled for testing purposes. Also, the current usage of these
associated functions is not truly stateless. Instead, their state is
hidden behind the hardware registers. This may be fine for the non test
code, where the generic Arch type parameter bounded by PageTableHal is
passed all the way from PageTable to PageTableHal implicitly. But its
usage complicates testing by forcing hacky global statics, and on top
of that, to keep those statics from pounding on each other forces to
serialize the tests with `serial_test`.

This commit converts every PageTableHal method from an associated
function to a &self method so tests can carry per instance state
instead of relying on globals. The arch instance is now plumbed
explicitly through the paging core rather than being invoked purely by
generic type.

No functional change to mapping/query/unmap behavior.

Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Replace the global ACTIVE/BASE statics in the paging unit tests with per
instance AtomicBool/AtomicU64 fields on DummyArch, shared with
DummyAllocator via Rc<DummyArch>. Each test now owns its own arch state
instead of mutating process wide globals, so the tests no longer
need #[serial] and can run in parallel.

This also makes the tests more useful under nextest.

Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
@vineelko
vineelko force-pushed the users/vineelko/remove_global_statics_0817 branch from ea29786 to 2e99976 Compare August 21, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants